@extends("/paging_template")
@import com.mgfireworks.mgplatform.mgadmin.product.model.Category
@import cn.hn.java.summer.utils.JsonUtils
@args List<Category> categoryList
	<s_panel>
		<s_title slot="title">产品类别列表</s_title>
		<input type="hidden" id="jsParentId" name="parentId"/>
		<input type="hidden" id="jsCatId" name="catId"/>
		<s_input name="parentName" id="jsParentName" value="无" text="所属类别" readonly="readonly"></s_input>
		<s_input name="catName" id="jsCatName" value="@val("catName")" text="类别名称"></s_input>
		<s_buttons slot="button" cols="3">
			<s_button type="link" icon="fa-plus" href="@url("add.html")">添加</s_button>
			<s_button id="jsBtnEdit" type="link" icon="fa-pencil" href="@url("edit.html?catId={0}")">修改</s_button>
			<s_button type="del" href="@url("del.json?catId={0}")">删除</s_button>
		</s_buttons>
	</s_panel>

		<div class="row">
			<div class="col-sm-12">
				<div id="jsProductCateTree"></div>
			</div>
			<div class="td_row_id" style="display: none"><input id="jsCheckedCate" type="checkbox"/></div>
		</div>
		
    @section(script){
       <script type="text/javascript">
       $(function(){
       	 var cateList=JSON.parse('@JsonUtils.toJson(categoryList)');
       	 var cateTree=module.category.genCateTree(cateList,"所有类别","0");
       
       	 $('#jsProductCateTree').treeview({
       	 	levels:10,
       	 	color: "#428bca",
			nodeIcon: "fa fa-leaf",
			showTags: true,
       	 	data:cateTree,
       	 	onNodeSelected:function(event, node){
       	 		var parent=$(this).treeview('getParent', node);
       	 		if(parent.length){
       	 			parent.value=0;
       	 			parent.text="无";
       	 		}
       	 		$("#jsParentId").val(parent.value);
       	 		$("#jsParentName").val(parent.text);
       	 		
       	 		$("#jsCatId").val(node.value);
       	 		$("#jsCatName").val(node.text);
       	 		
       	 		$("#jsCheckedCate").val(node.value).prop("checked",true);
       	 	}
       	 });
       
       	 //修改
       	 $("#jsBtnEdit").unbind("click").click(function(){
       	 	$.post("edit.json",$("form").serialize(),function(r){
       	 		if(r.result){
       	 			util.el.successAndReload("修改成功");
       	 		}else{
       	 			util.el.error("修改失败",r.data);
       	 		}
       	 	});
       	 	return false;
       	 });

       });
       </script>
       
    }
